package com.jx.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jx.model.User;
import com.jx.service.UserService;
import com.jx.servicrimpl.UserServiceImpl;

public class AddUserController extends HttpServlet{
	UserService adduser = new UserServiceImpl();
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
	// TODO Auto-generated method stub
	doPost(req, resp);
}
@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
	req.setCharacterEncoding("utf-8");
	PrintWriter  pw =  resp.getWriter();
	String uaccount = req.getParameter("uaccount");
	String upsw = req.getParameter("upsw");
	String ucard = req.getParameter("ucard");
	String uname = req.getParameter("uname");
	String usex = req.getParameter("usex");
	String uphone = req.getParameter("uphone");
	String uaddress = req.getParameter("uaddress");
	String upicture = req.getParameter("upicture");
	User uact=new User(uaccount);
	User user = new User(uaccount, upsw, ucard, uname, usex, uphone, uaddress, upicture);
	if (adduser.validateUser(uact) == true) {
		
	
	if (adduser.addUser(user)==true) {
		pw.write("1");
	}else {
		pw.write("0");
	}
	}
	else {
		pw.write("2");
	}
  
}
}
